import pkg from '../../../../package.json';
import calcBalance from './methods/calcBalance';
import ensureBalance from './methods/ensureBalance';
import initBalance from './methods/initBalance';
import modelsBuider from './models';
const { version } = pkg;
export { default as dealWithBalance } from './dealWithBalance';
export { default as ensureWithBalance } from './ensureWithBalance';
export { default as dealWithBalanceGQCMiddleware } from './dealWithBalanceGQCMiddleware';

export const plugin = {
	version,
	name: 'cm-billing',
	async register(server, options) {
		server.method('calcBalance', calcBalance, { bind: server });
		server.method('ensureBalance', ensureBalance, { bind: server });
		server.method('initBalance', initBalance, { bind: server });

		modelsBuider(server);

		server.methods.registerModulePermissions({
			module: 'billing',
			permissions: {
				getBalance: {
					id: 'getBalance',
					name: '获取套餐',
					defaultGrant: 1,
				},
				charge: {
					id: 'charge',
					name: '充值',
				},
				dealWithoutBilling: {
					id: 'dealWithoutBilling',
					name: '操作不判断套餐余额',
				},
			},
		});
	},
};

export default { plugin };
